import numpy as np
import matplotlib.pyplot as plt

# 设置图片清晰度
#plt.rcParams['figure.dpi'] = 300

# 定义复平面上的网格
x = np.linspace(-2, 2, 100)
y = np.linspace(-2 * np.pi, 2 * np.pi, 100)
X, Y = np.meshgrid(x, y)
Z = X + 1j * Y

# 计算复指数函数的值
W = np.exp(Z)

# 提取 Z 的实部、虚部、模和辐角
Z_real = np.real(Z)
Z_imag = np.imag(Z)
Z_magnitude = np.abs(Z)
Z_phase = np.angle(Z)

# 提取 W 的实部、虚部、模和辐角
W_real = np.real(W)
W_imag = np.imag(W)
W_magnitude = np.abs(W)
W_phase = np.angle(W)


# 创建一个 2x2 的子图布局，用于绘制 Z 的信息
fig1, axes1 = plt.subplots(2, 2, subplot_kw={'projection': 'polar'})
fig1.suptitle('Properties of Z in Polar Coordinates')

# 绘制 Z 的实部
axes1[0, 0].pcolormesh(Z_phase, Z_magnitude, Z_real, cmap='viridis')
axes1[0, 0].set_title('Real part of Z')

# 绘制 Z 的虚部
axes1[0, 1].pcolormesh(Z_phase, Z_magnitude, Z_imag, cmap='viridis')
axes1[0, 1].set_title('Imaginary part of Z')

# 绘制 Z 的模
axes1[1, 0].pcolormesh(Z_phase, Z_magnitude, Z_magnitude, cmap='viridis')
axes1[1, 0].set_title('Magnitude of Z')

# 绘制 Z 的辐角
axes1[1, 1].pcolormesh(Z_phase, Z_magnitude, Z_phase, cmap='viridis')
axes1[1, 1].set_title('Phase of Z')


# 创建一个 2x2 的子图布局，用于绘制 W 的信息
fig2, axes2 = plt.subplots(2, 2, subplot_kw={'projection': 'polar'})
fig2.suptitle('Properties of $e^Z$ in Polar Coordinates')

# 绘制 W 的实部
axes2[0, 0].pcolormesh(W_phase, W_magnitude, W_real, cmap='viridis')
axes2[0, 0].set_title('Real part of $e^Z$')

# 绘制 W 的虚部
axes2[0, 1].pcolormesh(W_phase, W_magnitude, W_imag, cmap='viridis')
axes2[0, 1].set_title('Imaginary part of $e^Z$')

# 绘制 W 的模
axes2[1, 0].pcolormesh(W_phase, W_magnitude, W_magnitude, cmap='viridis')
axes2[1, 0].set_title('Magnitude of $e^Z$')

# 绘制 W 的辐角
axes2[1, 1].pcolormesh(W_phase, W_magnitude, W_phase, cmap='viridis')
axes2[1, 1].set_title('Phase of $e^Z$')


plt.show()